<template>
    <rx-layout>
        <div slot="center" style>
            <rx-fit>
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <rx-list-title :title="i18n('list.myPending','我的挂起')"></rx-list-title>
                    <span class="search-btn-box">
                        <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
                    </span>
                </div>
                <div slot="searchbar" btnalign="right" v-if="fitSearch" @search="search" @cancel="cancel" @close="close">
                    <a-form layout="vertical">
                        <a-form-item :label="i18n('list.taskName','任务名称')">
                            <a-input :placeholder="i18n('msa.taskNameMsa','请输入任务名称')" v-model="queryParam.Q_TASK_NAME__S_LK"/>
                        </a-form-item>
                        <a-form-item :label="i18n('list.billNo','单据编号')">
                            <a-input :placeholder="i18n('msa.billNo','请输入业务单号')" v-model="queryParam.Q_BILL_NO__S_EQ"/>
                        </a-form-item>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :bordered="isBorder"
                    :multiSelect="true"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-bpm/bpm/core/bpmPendingRecord/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="id"
                    @selectChange="onSelectChange"
                >
                      <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                          <span  v-if="!record.endTime" @click="handleTask(record)">{{i18n('list.handle','办理')}}</span>
                          <span v-else @click.stop="onDetail(record)">{{$ti18('rxList.detailBtn','明细')}}</span>
                      </span>
                </rx-grid>
            </rx-fit>

        </div>
    </rx-layout>
</template>

<script>
import BpmPendingRecordApi from '@/api/bpm/core/bpmPendingRecord'
import {BaseList, RxFit, RxGrid} from '@lowcode/jpaas-common-lib';
import userState from "@/assets/js/userState";
import FlowUtil from "@/views/modules/bpm/js/FlowUtil";
import BpmtaskApi from "@/api/bpm/core/bpmTask";

export default {
    name: 'BpmPendingRecordList',
    mixins: [BaseList,userState,FlowUtil],
    components: {
        RxFit
    },
    data() {
        return {
            columns: [
                {
                    title: this.$ti18('rxList.index','序号'),
                    type: 'indexColumn',
                    width: 40,
                    dataIndex: 'serial',
                    scopedSlots: {customRender: 'serial'}
                },
                {title: this.i18n('list.taskName','任务名称'), dataIndex: 'taskName', width: 240},
                {title: this.i18n('list.billNo','单据编号'), dataIndex: 'billNo', width: 120},


                {title: this.i18n('list.nodeName','挂起环节'), dataIndex: 'nodeName', width: 120},
                {title:this.i18n('list.startTime','开始时间'), dataIndex: 'startTime', width: 100},
                {title:this.i18n('list.endTime','结束时间'), dataIndex: 'endTime', width: 100},
                {title: this.$ti18('rxList.action','操作'), width: 40, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
            ]
        }
    },
    created() {
        this.queryParam["Q_CREATE_BY__S_EQ"]=this.user.userId;
        let appId=this.curApp.appId;
        if (appId){
            this.queryParam["Q_APP_ID__S_EQ"]=appId;
        }
    },
    methods: {
        i18n(name,text,key){
            return this.$ti18(name,text,"MyPending",key);
        },
        getListByParams(parameter) {
            return BpmPendingRecordApi.query(parameter)
        },
        handleTask(record) {
            this.openInst(record.appId,record.instId,record.taskId);
        },
        restoreTask(record){
            BpmtaskApi.taskPendingOrRestore(taskId,this.visiableType,this.opinion).then(res=>{
                if(res.success){
                    window.location.reload();
                }
            });
        },
        onDetail(record) {
            this.openDetail(record.appId,record.instId,"");
        },
        resetSearch() {
            this.queryParam = {};
            this.queryParam["Q_CREATE_BY__S_EQ"]=this.user.userId;
            let appId=this.curApp.appId;
            if(this.hasAppId && appId){
                this.queryParam.Q_APP_ID__S_EQ=appId;
            }
            this.$nextTick(() => {
                this.$refs['table'].loadData();
            })
        },
    }
}
</script>
<style scoped>
.table-operator {
    padding: 4px;
}

.table-operator button {
    margin: 2px;
}
</style>

